import axios from 'axios'
import { APPCODE } from './config'
// 远程获取新闻和新闻类别数据

/**
 * 获取所有的新闻类别
 */
export async function getNewsChannels () {
  var resp = await axios.get('/mock/channellist.json', {
    headers: {
      Authorization: `APPCODE ${APPCODE}`
    }
  })
  // console.log(resp.data.showapi_res_body.channelList)
  return resp.data.showapi_res_body.channelList
}

/**
 * 按照频道, 分页获取新闻
 * @param {*} channelId 新闻频道id，必须精确匹配
 * @param {*} page 页数，默认1。每页最多20条记录
 * @param {*} maxResult 每页最大请求数,默认是20
 */
export async function getNews (channelId, page, maxResult) {
  var resp = await axios.get('/mock/newslist.json', {
    headers: {
      Authorization: `APPCODE ${APPCODE}`
    },
    params: {
      channelId,
      page,
      maxResult,
      needAllList: false,
      needContent: 1
    }
  })
  // console.log(resp.data.showapi_res_body.pagebean)
  return resp.data.showapi_res_body.pagebean
}

// getNewsChannels()
// getNews('123456')
